﻿namespace com.stifel.BranchMgmt
{
    using System.Linq;

    using com.stifel.BranchMgmtDao;
    using com.stifel.Extensions.SymbolExtensions;
    using com.stifel.SharePoint;

    using Microsoft.SharePoint;

    public class StifelBranchUnit_Definition : StifelBaseDefinition
    {
        #region Fields

        const string SITECOLUMNS = "Stifel-BranchUnit.xml";

        #endregion Fields

        #region Constructors

        public StifelBranchUnit_Definition( SPFeatureReceiverProperties properties )
            : base(properties)
        {
        }

        ~StifelBranchUnit_Definition( )
        {
            Dispose( false );
        }

        #endregion Constructors

        #region Methods

        public override void Create( )
        {
            base.Create( );
            CreateSiteColumns( GetFieldDefinitionsAsXml( SITECOLUMNS ) );
            CreateContentType( getContentTypeDefn( ) );
            CreateList( getListDefn( ) );
        }

        public override void Delete( )
        {
            base.Delete( );
            DeleteList( getListDefn( ), false );
            DeleteContentType( getContentTypeDefn( ) );
            DeleteSiteColumns( GetFieldDefinitionsAsXml( SITECOLUMNS ) );
        }

        ContentTypeDefn getContentTypeDefn( )
        {
            StifelBranchUnit c = null;
            return new ContentTypeDefn
            {
                Name = Item.GetContentTypeName<StifelBranchUnit>( ),
                ContentTypeId = Item.GetContentTypeId<StifelBranchUnit>( ),
                WebLevel = true,
                Group = "Stifel",
                Description = "Describes a branch unit.",
                Fields = new FieldDefn[ ] {
                    new FieldDefn{
                        Name=Item.GetColumnName<StifelBranchUnit>(c.GetPropertySymbol(a=>a.BranchLookupId)),
                        Required=true
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<StifelBranchUnit>(c.GetPropertySymbol(a=>a.DestinationCheckCode))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<StifelBranchUnit>(c.GetPropertySymbol(a=>a.DestinationCode))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<StifelBranchUnit>(c.GetPropertySymbol(a=>a.DestinationWireCode))
                    },
                    new FieldDefn{
                        Name=Item.GetColumnName<StifelBranchUnit>(c.GetPropertySymbol(a=>a.ORG))
                    }
                }.Distinct( ).ToList( )
            };
        }

        ListDefn getListDefn( )
        {
            return new ListDefn
            {
                RootFolderName = StifelBranchUnitDao.ListName,
                Title = "Stifel Branch Unit",
                Description = "Contains branch associated unit information.",
                ContentTypes = new string[ ] {
                    Item.GetContentTypeName<StifelBranchUnit>()
                }.ToList( )
            };
        }

        void loadList( )
        {
        }

        #endregion Methods
    }
}